package com.xyyy.xymusic;

import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.xyyy.xyplayer.listener.XYOnPcmInfoListener;
import com.xyyy.xyplayer.listener.XYOnPreparedListener;
import com.xyyy.xyplayer.log.LogUtil;
import com.xyyy.xyplayer.player.XYplayer;

public class CutActivity extends AppCompatActivity {

    private XYplayer xYplayer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cut);

        xYplayer = XYplayer.getInstance();
        xYplayer.setXyOnPreparedListener(new XYOnPreparedListener() {
            @Override
            public void onPrepared() {
                LogUtil.d("准备好了开始裁剪");
                xYplayer.cutAudioPlay(20, 40, true);
            }
        });

        xYplayer.setXyOnPcmInfoListener(new XYOnPcmInfoListener() {
            @Override
            public void onPcmInfo(byte[] buffer, int buffersize) {

                LogUtil.d("buffersize = " + buffersize);

            }

            @Override
            public void onPcmRate(int samperate) {
                LogUtil.d("采样率 = "+samperate);
            }
        });
    }

    public void cut(View view) {
        String url = Environment.getExternalStorageDirectory() + "/xjw.mp3";
        LogUtil.d("裁剪url = " + url);
        xYplayer.setSource(url);
//        xYplayer.setSource("/mnt/sdcard/xjw.mp3");

        xYplayer.prepared();
    }
}
